import { customRef } from "vue";

export default function useMsgRef(
  initVal: string = "",
  timeOut: number = 1000,
) {
  let t: number;

  return customRef((track, trigger) => {
    return {
      get() {
        track();
        return initVal;
      },
      set(value) {
        clearTimeout(t);
        t = setTimeout(() => {
          initVal = value;
          trigger();
        }, timeOut);
      },
    };
  });
}
